package com.fer.service.impl;

import com.fer.mapper.StaffMapper;
import com.fer.model.Staff;
import com.fer.service.StaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class StaffServiceImpl implements StaffService {

    @Autowired
    private StaffMapper staffMapper;

    @Override
    public List<Staff> findStaff(String staff_name,Integer shop_id) {

        if (staff_name!=null){
            StringBuffer sb = new StringBuffer();
            sb.append("%");
            sb.append(staff_name);
            sb.append("%");
            staff_name = sb.toString();
        }
        return staffMapper.findStaff(staff_name,shop_id);
    }

    @Override
    @Transactional(isolation = Isolation.READ_COMMITTED,propagation = Propagation.REQUIRED)
    public void addStaff(Staff staff) {
        staffMapper.addStaff(staff);

    }

    @Override
    public void deleteStaff(Integer staff_id) {
        staffMapper.deleteStaff(staff_id);

    }

    @Override
    public Boolean modifyStaff(Staff staff) {
        Boolean result=staffMapper.modifyStaff(staff);
        if(result==false){
            return false;
        }
        return true;
    }
}
